table.insert(itemActions,
	function(item, action)
		-- RARE Shields rev 1.3b 07/24/08
		-- By Kel. Extensively uses existing PR code not by me.
		-- see: dir .. "readme.txt" for information regarding these variables
		local priority = 6
		local identify = true
		local dump = false

		if not isRareShield(item) then
			return false
        elseif action == aPICK and (not item.flags.Identified or isGoodRareShield(item)) then
			return priority
		elseif action == aIDENT then
			return identify
		elseif action == aSELL and item.flags.Identified and not isGoodRareShield(item) then
			return true
		elseif action == aDUMP and item.flags.Identified and not isGoodRareShield(item) then
			return dump
		end

		return false
	end
)


-- We want to keep Light & Medium Elites having best Defense and CTB for each class and lowest Str req.
-- Grim Shield listed cos its Def can exceed some elites and has comparable CTB.
-- Dragon Shield listed cos its low StrReq + high CTB make a good Monarch substitute.
-- Comment those two exceptional shields if you don't want to pick them.

function isRareShield(item)
   		 if  (
    	     (item.quality == ItemQuality.Rare) and -- Item must be Rare AND one of these items
       		 (item.baseItem.code == "uit" or 		-- Monarch
         	 item.baseItem.code == "ush" or 		-- Troll Nest
         	 --item.baseItem.code == "urg" or 		-- Hyperion
         	 --item.baseItem.code == "upk" or 		-- Blade Barrier
         	 --item.baseItem.code == "xit" or 		-- Dragon Shield. Think Monarch w/Lower Str.
         	 --item.baseItem.code == "xsh" or 		-- Grim Shield. Best hi-defense exceptional.
         	 
-- Comment out 10 pally shield lines below and uncomment the bottom line
-- with ItemKind.AuricShields to pick ALL Pally shields, even crap. (targe, heraldric)

         	 --item.baseItem.code == "pa6" or 		-- Pally: Akaran Targe
         	 --item.baseItem.code == "pa7" or 		-- Pally: Akaran Rondache
         	 --item.baseItem.code == "pa8" or 		-- Pally: Protector Shield
         	 item.baseItem.code == "pa9" or 		-- Pally: Gilded Shield
         	 item.baseItem.code == "paa" or 		-- Pally: Royal Shield
         	 item.baseItem.code == "pab" or 		-- Pally: Sacred Targe
         	 item.baseItem.code == "pac" or 		-- Pally: Sacred Rondache
         	 item.baseItem.code == "pad" or 		-- Pally: Kurast Shield
         	 item.baseItem.code == "pae" or 		-- Pally: Zakarum Shield
         	 item.baseItem.code == "paf")		 	-- Pally: Vortex Shield
         	 --item.baseItem.baseType.Type == ItemKind.AuricShields) -- All Rare Pally shields
		 	 ) then
		return true
	end
  
  return false

end


function isGoodRareShield(item)  -- Check for good rare shields
     local fbr, str, life, fhr, def, dblvl, repair = false, false, false, false, false, false, false
     local allskill, skilltab = false, false --Pally Skills
     local dualres, trires, allres = false, false, false

	 --Set Thresholds for Resists
	 dualres = hasRes(item, 25, 2) -- 2 resists of 25-30%
     trires = hasRes(item, 20, 3) -- 3 resists of 20-30%
     allres = hasRes(item, 16, 4) -- 4 resists of 12-30%
	
	
	for i = 0, item.mods:size() - 1 do
		if (item.mods[i].Stat.Type == StatType.FasterBlockRate and
				item.mods[i].Value ==30) then -- 15-30% FBR (Blocking/Deflecting)
			fbr = true
		elseif (item.mods[i].Stat.Type == StatType.Strength and
				item.mods[i].Value >=8) then -- +8-9 Str (Ox)
			str = true
		elseif (item.mods[i].Stat.Type == StatType.MaxLife and
				item.mods[i].Value >=35) then -- +35-40 life (Mammoth)
			life = true
		elseif (item.mods[i].Stat.Type == StatType.FasterHitRecovery and
				item.mods[i].Value >=17) then -- 17% FHR (of Balance/Equilibrium)
			fhr = true
		elseif (item.mods[i].Stat.Type == StatType.DefensePercent and
				item.mods[i].Value >=171) then -- 171-200% Enhanced Defense (Holy/Godly)
			def = true
		elseif (item.mods[i].Stat.Type == StatType.ArmorPerLevel and
            item.mods[i].PerLevel >=3) then -- 3-4 def/lvl (Faithful)
			dblvl = true
		elseif  (item.mods[i].Stat.Type == StatType.ReplenishDurability and
            	item.flags.Ethereal) then  --  Eth + Auto-Repair (Self-Repair/Restoration)
			repair = true
		elseif (item.mods[i].Stat.Type == StatType.ClassSkillsBonus and
				item.mods[i].Value >=2) then -- +2 Pally Skills (Priest's)
			allskill = true
		elseif  (item.mods[i].Stat.Type == StatType.SkillTabBonus and
				item.mods[i].Value >=2) then --  +2 to Pally Skilltab (Hawk/Warden/Commander's)
			skilltab = true
		end
end

return 
	(
	
    (def and (life or fhr or fbr)) or 	-- 81-200% def + second mod
	((dualres or trires or allres) and (fbr or def or life or fhr or str)) or -- Dual res + second mod
	repair and (def or life or fhr or fbr or str or dualres or trires or allres) or	-- Eth + Auto-Repair + mod - testing
	(allskill or skilltab and (life or fhr or fbr or def or dualres or trires or allres)) -- +2 pal/tree + mod
	
	)
    
end


-- GOOD RARE SHIELD AFFIXES ----------------------
--------------------------------------------------
-- PREFIXES
--------------------------------------------------
-- Faithful			4 def/Level (4-396)
-- Holy				81-100% Defense
-- Godly			101-200% Defense
-- Scintillating	12-15% All Resists
-- Prismatic 		16-20% All Resists
-- Lap/Rus/Och/Viri 11-20% Single Resist
-- Cob/Gar/Cor/Jade 21-30% Single resist
-- Mechanic's 		1-2 sockets
-- Priest's 		+2 Paladin Skills
-- Hawk/Wrdn/Cmdrs 	+2 Pally Skill Tree
--------------------------------------------------
-- SUFFIXES
--------------------------------------------------
-- Blocking 		10% Block 15% FBR
-- Deflecting 		20% Block 30% FBR
-- Equilibrium 		17% FHR
-- Life             4-7 Damage Reduction
-- Mammoth 			31-40 to Life
-- Ox               6-9 Strength
-- Regeneration	    3-5 Replenish Life
-- Self-Repair	 	Repair 1 Durability-33Sec
-- Restoration	 	Repair 1 Durability-20Sec
-- Thawing       	Half Freeze duration
---------------------------------------------------
